package com.cidp.system.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;
import org.extremecomponents.table.limit.Limit;

import com.cidp.system.model.ToperatorDetail;
import com.cidp.system.pojo.OperatorDetailPo;
import com.cidp.system.service.IOperatorDetailService;
import com.litt.core.common.Constants;
import com.litt.core.page.IPageList;
import com.litt.core.page.PagePoParam;
import com.litt.core.util.ExtremeTableUtil;
/**
 * <b>标题：</b>操作员详细信息管理action类.
 * <pre><b>描述</b>
 *    操作员管理
 * </pre>
 * 
 * @author zhanglei 
 * @since 2008-6-3
 * @version 1.0
 */
public class OperatorDetailAction extends DispatchAction{
	
	private IOperatorDetailService operatorDetailService;
	/**
	 * 查询
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward search(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		DynaActionForm dynaActionForm=(DynaActionForm) form;
		OperatorDetailPo operatorDetailPo=(OperatorDetailPo)dynaActionForm.get("operatorDetailPo");
		Limit limit=ExtremeTableUtil.getLimit(request,Constants.DEFAULT_PAGE_SIZE);
		IPageList page = operatorDetailService.listByPage(new PagePoParam(operatorDetailPo, limit.getPage(), limit.getCurrentRowsDisplayed()));
		request.setAttribute("resultList", page.getRsList());
		request.setAttribute("totalRows", new Integer(page.getTotalSize()));
		return mapping.findForward("operatorDetailList");
	}
	/**
	 * 增加
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward add(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		return mapping.findForward("operatorDetailAdd");
	}
	/**
	 * 保存
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward save(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		DynaActionForm dynaActionForm=(DynaActionForm) form;
		OperatorDetailPo operatorDetailPo=(OperatorDetailPo)dynaActionForm.get("operatorDetailPo");
		ToperatorDetail operatorDetail=new ToperatorDetail();
		operatorDetail.setOpId(operatorDetailPo.getOpId());
		operatorDetail.setLoginId(operatorDetailPo.getLoginId());
		operatorDetail.setPersonalSign(operatorDetailPo.getPersonalSign());
		operatorDetail.setPersonalIntro(operatorDetailPo.getPersonalIntro());
		operatorDetail.setPersonalPic(operatorDetailPo.getPersonalPic());
		operatorDetail.setMsn(operatorDetailPo.getMsn());
		operatorDetail.setQq(operatorDetailPo.getQq());
		operatorDetail.setAddress(operatorDetailPo.getAddress());
		operatorDetail.setPostNo(operatorDetailPo.getPostNo());
		operatorDetailService.save(operatorDetail);
		return mapping.findForward("success");
	}
	/**
	 * 編輯
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward edit(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		DynaActionForm dynaActionForm=(DynaActionForm) form;
		OperatorDetailPo operatorDetailPo=(OperatorDetailPo)dynaActionForm.get("operatorDetailPo");
		String sId=request.getParameter("id");
		ToperatorDetail operatorDetail=operatorDetailService.loadById(sId);
		BeanUtils.copyProperties(operatorDetailPo,operatorDetail);
		if(operatorDetailPo.getPostNo()!=null && operatorDetailPo.getPostNo().toString().equals("0")){
			operatorDetailPo.setPostNo(null);
		}
		dynaActionForm.set("operatorDetailPo", operatorDetailPo);
		return mapping.findForward("operatorDetailEdit");
	}
	/**
	 * 修改
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward update(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		DynaActionForm dynaActionForm=(DynaActionForm) form;
		OperatorDetailPo operatorDetailPo=(OperatorDetailPo)dynaActionForm.get("operatorDetailPo");
		ToperatorDetail operatorDetail=operatorDetailService.load(operatorDetailPo.getSerialNo());
		if(operatorDetailPo.getPostNo()!=null && operatorDetailPo.getPostNo().toString().equals("0")){
			operatorDetailPo.setPostNo(null);
		}
		operatorDetail.setOpId(operatorDetail.getOpId());
		operatorDetail.setLoginId(operatorDetailPo.getLoginId());
		operatorDetail.setPersonalSign(operatorDetailPo.getPersonalSign());
		operatorDetail.setPersonalIntro(operatorDetailPo.getPersonalIntro());
		operatorDetail.setPersonalPic(operatorDetailPo.getPersonalPic());
		operatorDetail.setMsn(operatorDetailPo.getMsn());
		operatorDetail.setQq(operatorDetailPo.getQq());
		operatorDetail.setAddress(operatorDetailPo.getAddress());
		operatorDetail.setPostNo(operatorDetailPo.getPostNo());
		operatorDetailService.update(operatorDetail);
		return mapping.findForward("success");
	}
	public void setOperatorDetailService(IOperatorDetailService operatorDetailService) {
		this.operatorDetailService = operatorDetailService;
	}
}
